package com.asamioffice.goldenport.text

/**
 * @since   Sep. 28, 2010
 * @version Oct. 12, 2010
 * @author  ASAMI, Tomoharu
 */
object StringUtil {
  def liftString(s: String) = {
    if (s == null) ""
    else s
  }

  def makeShortString(data: Any): String = {
    makeShortString(data, 40)
  }

  def makeShortString(data: Any, length: Int): String = {
    val buf = new StringBuilder
    buildShortString(data, length, buf)
    buf.toString
  }

  def buildShortString(data: Any, length: Int, buf: StringBuilder) {
    val s = data.toString
    if (s.length > length) {
      buf.append(s.substring(0, length))
      buf.append("...")
    } else {
      buf.append(s)
    }
  }
}
